package com.tcxr.server;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tcxr.biz.ThemeBiz;
import com.tcxr.entity.Login;
import com.tcxr.entity.Theme;
import com.tcxr.framework.base.ServerBase;
import com.tcxr.vo.LoginView;
import com.tcxr.vo.ThemeView;

 
@Service
public class ThemeServer extends ServerBase {
	@Autowired 
	private ThemeBiz themeBiz;
	
	/**
	 * 首页的翻页信息
	 * @param page第几页
	 * @param eachPage这一页有多少
	 * @return
	 */
	public List<ThemeView> getIndex(int page, int eachPage)
	{
	 List<Theme>	themeList=themeBiz.getThemePage(page, eachPage,1,1);
	 List<ThemeView> themeViewsList=new ArrayList<ThemeView>();
	 ThemeView themeView=null;
	 
	 for (Theme theme : themeList) {
		 themeView=new ThemeView();
		 themeView.setThContent(theme.getThContent());
		 themeView.setThId(theme.getThId());
		 themeView.setThLoginId(theme.getLogin().getLoId());
		 themeView.setThPublishedDate(theme.getThPublishedDate());
		 themeView.setThStatus(theme.getThStatus());
		 themeView.setThTitle(theme.getThTitle());
		 themeView.setThType(theme.getThType());
		 themeView.setThUp(theme.getThUp());
		 themeView.setLoId(theme.getLogin().getLoId());
		 themeView.setLoName(theme.getLogin().getLoName());
		 themeView.setLoImg(theme.getLogin().getLoImg());
		 themeViewsList.add(themeView);
		
	  }
	
	  return themeViewsList;
	 
	}
	/**
	 * 添加一个主题内容
	 * @param themeView
	 * @return
	 */
	public int  addTheme(ThemeView themeView)
	{
		Theme theme=new Theme();
		theme.setThTitle(themeView.getThTitle());
		theme.setThContent(themeView.getThContent());
		theme.setThStatus(1);
		theme.setThType(1);
		theme.setThUp(0);
		
		Login login = new Login();
		login.setLoId(((LoginView)super.getSessionUser()).getLoId());
		theme.setLogin(login);
		
		
		
		return themeBiz.insertTheme(theme);
	}
	
	
	
	
	
	
	
	
	public int  getCountTheme()
	{
		return themeBiz.getCountTheme();
	}

}
